import request from './request'

/**
 * 关注用户
 * @param {string} userId - 被关注用户ID
 * @returns {Promise<Object>} - 包含关注信息的响应
 */
export const followUser = async (userId) => {
  return request.post(`/users/${userId}/follow`)
}

/**
 * 取消关注用户
 * @param {string} userId - 被取消关注用户ID
 * @returns {Promise<Object>} - 响应结果
 */
export const unfollowUser = async (userId) => {
  return request.delete(`/users/${userId}/follow`)
}

/**
 * 获取用户的粉丝列表
 * @param {string} userId - 用户ID
 * @param {Object} params - 查询参数（如分页）
 * @returns {Promise<Array>} - 粉丝列表
 */
export const fetchUserFollowers = async (userId, params = {}) => {
  return request.get(`/users/${userId}/followers`, { params })
}

/**
 * 获取用户的关注列表
 * @param {string} userId - 用户ID
 * @param {Object} params - 查询参数（如分页）
 * @returns {Promise<Array>} - 关注列表
 */
export const fetchUserFollowing = async (userId, params = {}) => {
  return request.get(`/users/${userId}/following`, { params })
}

/**
 * 检查当前用户是否关注了指定用户
 * @param {string} userId - 用户ID
 * @returns {Promise<boolean>} - 是否关注
 */
export const checkFollowingStatus = async (userId) => {
  try {
    await request.get(`/users/${userId}/following-status`)
    return true
  } catch (error) {
    return false
  }
}